#!/usr/bin/python
# -*- coding: UTF-8 -*-
# @Time    : 2023/11/17 09:48
# @Author  : 飞飞
from django import forms
from .models import CustomerDetail


class RegisterForm(forms.Form):
    email = forms.CharField(
        required=True,
        widget=forms.EmailInput(attrs={
            'lay - verify': "title",
            'autocomplete': "off",
            'placeholder': "请输入邮箱账号",
            'class': "layui-input",
        }),
        error_messages={
            'required': '邮箱地址不能为空',
            'invalid': '邮箱格式不正确'
        }
    )
    password = forms.CharField(
        required=True,
        min_length=6,
        max_length=12,
        widget=forms.PasswordInput(attrs={
            'lay - verify': "pass",
            'autocomplete': "off",
            'placeholder': "请输入6-12位密码",
            'class': "layui-input",
        }),
        error_messages={
            'required': '密码不能为空',
            'min_length': '密码最小长度应为6位',
            'max_length': '密码最大长度应为12位',
        }
    )
    re_pass = forms.CharField(
        required=True,
        widget=forms.PasswordInput(attrs={
            'lay - verify': "re_pass",
            'autocomplete': "off",
            'placeholder': "请确认密码",
            'class': "layui-input",
        }),
        error_messages={
            'required': '确认密码不能为空',
        }
    )
    verify = forms.CharField(
        required=True,
        widget=forms.TextInput(attrs={
            'lay - verify': "verify",
            'autocomplete': "off",
            'placeholder': "请输入邮箱验证码",
            'class': "layui-input code",
        }),
        error_messages={
            'required': '验证码不能为空',
        }
    )


class LoginForm(forms.Form):
    email = forms.CharField(
        required=True,
        widget=forms.EmailInput(attrs={
            'lay - verify': "title",
            'autocomplete': "off",
            'placeholder': "请输入邮箱账号",
            'class': "layui-input",
        }),
        error_messages={
            'required': '邮箱地址不能为空',
            'invalid': '邮箱格式不正确'
        }
    )
    password = forms.CharField(
        required=True,
        min_length=6,
        max_length=12,
        widget=forms.PasswordInput(attrs={
            'lay - verify': "pass",
            'autocomplete': "off",
            'placeholder': "请输入6-12位密码",
            'class': "layui-input",
        }),
        error_messages={
            'required': '密码不能为空',
            'min_length': '密码最小长度应为6位',
            'max_length': '密码最大长度应为12位',
        }
    )
    re_pass = forms.CharField(
        required=True,
        widget=forms.PasswordInput(attrs={
            'lay - verify': "re_pass",
            'autocomplete': "off",
            'placeholder': "请确认密码",
            'class': "layui-input",
        }),
        error_messages={
            'required': '确认密码不能为空',
        }
    )
    verify = forms.CharField(
        required=True,
        widget=forms.TextInput(attrs={
            'lay - verify': "verify",
            'autocomplete': "off",
            'placeholder': "请输入图片验证码",
            'class': "layui-input code",
        }),
        error_messages={
            'required': '验证码不能为空',
        }
    )


class UserInfoModelForm(forms.ModelForm):
    class Meta:
        model = CustomerDetail
        fields = '__all__'
        widgets = {
            'nickname': forms.TextInput(attrs={
                'placeholder': "请输入昵称",
                'autocomplete': "off",
                'class': "layui-input",
            }),
            'phone': forms.TextInput(attrs={
                'placeholder': "请输入手机号码",
                'autocomplete': "off",
                'class': "layui-input",
            }),
            'age': forms.NumberInput(attrs={
                'placeholder': "请输入年龄",
                'autocomplete': "off",
                'class': "layui-input",
            }),
            'sex': forms.RadioSelect(
                choices=((0, '女'), (1, '男'))
            ),
            'address': forms.TextInput(attrs={
                'placeholder': "请输入地址",
                'autocomplete': "off",
                'class': "layui-input",
            }),
            'birthday': forms.DateInput(
                format='%Y-%m-%d',  # 设置渲染格式
                attrs={
                    'placeholder': "请输入生日日期",
                    'autocomplete': "off",
                    'class': "layui-input",
                }
            ),
        }



